package org.de.maeyer.statistic;

/**
 * @author Peter De Maeyer
 */
public class LinkedDoubleCategory extends DoubleCategory {
	
	private final DoubleCategory nextCategory;
	
	public LinkedDoubleCategory(double inclusiveLowerBound, long count, DoubleCategory nextCategory) {
	    super(inclusiveLowerBound, count);
	    this.nextCategory = nextCategory;
    }
	
	@Override
	public boolean contains(Object value) {
	    double doubleValue = ((Number) value).doubleValue();
	    return doubleValue >= inclusiveLowerBound && doubleValue < nextCategory.inclusiveLowerBound;
	}
	
	@Override
	public double getWidth() {
	    return nextCategory.inclusiveLowerBound - inclusiveLowerBound;
	}
	
	@Override
	public double getDensity() {
	    return count / getWidth();
	}
}
